package com.example.a1.fannong.ui.shoppingcart;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.a1.fannong.R;
import com.example.a1.fannong.core.app.BaseActivity;
import com.example.a1.fannong.view.MyActionBar;
import com.lljjcoder.city_20170724.CityPickerView;
import com.lljjcoder.city_20170724.bean.CityBean;
import com.lljjcoder.city_20170724.bean.DistrictBean;
import com.lljjcoder.city_20170724.bean.ProvinceBean;

import cn.personal.library.viewinject.FindViewById;
import cn.personal.library.viewinject.OnClick;
import cn.personal.library.viewinject.ViewInjecter;

public class AddressActivity extends BaseActivity {

    @FindViewById(R.id.top_bar)
    private MyActionBar myActionBar;
    @FindViewById(R.id.xzdz_tv)
    private TextView selectAddTv;

    private String tag;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_address);
        ViewInjecter.inject(this);
        initData();

    }

    private void initData() {
        Intent intent = getIntent();
        if (intent != null) {
            tag = intent.getStringExtra("tag");
        }

        if (tag.equals("0")) {
            myActionBar.setTitle("新建地址");
        } else {
            myActionBar.setTitle("编辑地址");
        }
    }

    @OnClick({R.id.xzdz_layout})
    public void onItemClick(View view) {
        switch (view.getId()) {
            case R.id.xzdz_layout:
                CityPickerView cityPicker = new CityPickerView.Builder(AddressActivity.this).textSize(18)
                    .titleTextColor("#000000")
                    .backgroundPop(0xa0000000)
                    .confirTextColor("#000000")
                    .cancelTextColor("#000000")
                    .province("上海")
                    .city("上海")
                    .district(" ")
                    .textColor(Color.parseColor("#5a5a5a"))
                    .provinceCyclic(true)
                    .cityCyclic(false)
                    .districtCyclic(false)
                    .visibleItemsCount(7)
                    .itemPadding(10)
                    .build();
                cityPicker.show();
                cityPicker.setOnCityItemClickListener(new CityPickerView.OnCityItemClickListener() {
                    @Override
                    public void onSelected(ProvinceBean province, CityBean city, DistrictBean district) {
                        //返回结果
                        selectAddTv.setText( province.getName() + " " + city.getName() + "  " + district.getName());
                    }
                    @Override
                    public void onCancel() {}
                });
                break;
        }
    }

    public static void startActivity(Context context, String tag) {
        Intent intent = new Intent(context, AddressActivity.class);
        intent.putExtra("tag", tag);
        context.startActivity(intent);
    }
}
